package com.canlihao.ui.utils.glide;

import android.content.Context;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.canlihao.ui.R;


public class GlideLoadUtil {
    private static GlideLoadUtil glideLoadUtil;


    public static GlideLoadUtil getLoadUtil() {
        if (glideLoadUtil == null) {
            glideLoadUtil = new GlideLoadUtil();
        }
        return glideLoadUtil;
    }

    private GlideLoadUtil() {
    }

    public void loadImage(Context context, GlideConfig glideConfig) {
//            Picasso.get().load(glideConfig.getUrl())
//                    .into(glideConfig.getImageView());

        RequestOptions options = new RequestOptions();
        options.centerCrop()
                .placeholder(glideConfig.getPlaceHold())
                .error(glideConfig.getPlaceHold());
        Glide.with(context).applyDefaultRequestOptions(options).load(glideConfig.getUrl()).into(glideConfig.getImageView());

    }
    public void loadImage2(Context context, GlideConfig glideConfig) {
//            Picasso.get().load(glideConfig.getUrl())
//                    .into(glideConfig.getImageView());

        RequestOptions options = new RequestOptions();
        options
                .placeholder(glideConfig.getPlaceHold())
                .error(glideConfig.getPlaceHold());
        Glide.with(context).applyDefaultRequestOptions(options).load(glideConfig.getUrl()).into(glideConfig.getImageView());

    }
    public void loadFilletImage(Context context, GlideConfig glideConfig) {
        RequestOptions options = new RequestOptions()
                        .centerCrop()
                         .placeholder(glideConfig.getPlaceHold())
                        .error(glideConfig.getPlaceHold())
                         .transform(new GlideRoundTransform(5)); //圆角
        Glide.with(context).applyDefaultRequestOptions(options).load(glideConfig.getUrl()).into(glideConfig.getImageView());

    }
    public void loadImageSmall(Context context, GlideConfig glideConfig, int width, int height) {
//            Picasso.get().load(glideConfig.getUrl())
//                    .into(glideConfig.getImageView());

        RequestOptions options = new RequestOptions();
        options.centerCrop()
                .placeholder(glideConfig.getPlaceHold())
                .error(glideConfig.getPlaceHold())
                .override(width,height);
        Glide.with(context) .applyDefaultRequestOptions(options).load(glideConfig.getUrl()).into(glideConfig.getImageView());

    }
    public void loadCircleImage(Context context, GlideConfig glideConfig) {
//            Picasso.get().load(glideConfig.getUrl())
//                    .into(glideConfig.getImageView());

        RequestOptions options = new RequestOptions();
        options.centerCrop()
                .circleCrop()
                .placeholder(R.mipmap.ic_launcher)
                .error(R.mipmap.ic_launcher);
        Glide.with(context).applyDefaultRequestOptions(options).load(glideConfig.getUrl()).into(glideConfig.getImageView());

    }

}
